module Main where

import System.Environment(getArgs)
import System.FilePath(replaceExtension)
import Types
import Parser
import qualified Printer
import qualified CudaPrinter
import Translator


main = do
    args <- getArgs
    case length args of
        1 -> do
            let file = head args
            prog <- parse file
            writeFile (replaceExtension file "cu") $ CudaPrinter.printProgram $ translate prog
        2 -> do
            let file = args !! 0
            let opt = args !! 1
            case opt of
                "-dp" -> parseTest file
                _ -> do
                    prog <- parse file
                    case opt of
                        "-d0" -> print prog
                        "-d1" -> putStrLn $ Printer.printProgram prog
                        "-d2" -> putStrLn $ Printer.printProgram $ translate prog
                        "-d3" -> putStrLn $ CudaPrinter.printProgram $ translate prog
                        ('-':_) -> error "bad option"
                        out -> writeFile out $ CudaPrinter.printProgram $ translate prog
        _ -> putStrLn "wrong number of arguments"


